<?php
namespace System\Controller;
use Common\Controller\BaseController;
class SysActionController extends BaseController{
	const modelName = CONTROLLER_NAME;
	
	protected function _initialize(){
		parent::_initialize();
		
		$this->checkAuth();
		
		$this->model = D(self::modelName);
	}
	
	public function index(){
        if(IS_AJAX){
            //排序
            $order = I('get.order');

            //获取列表
            $field = "pk_id,name,action,IF(type=1,'菜单节点','系统节点') AS type,create_time";
            $map['is_del'] = 0;
            $data = $this->getRows(self::modelName, $map ,$field ,1 ,$order);
            $this->data = $data;
            $this->rtnResult(0);
        }else{
            //表头、字段名
            $fieldArr = "pk_id,name,action,type,create_time";
            $data['field'] = $fieldArr;
            $data['titleArr'] = array('编号','节点名','英文名','类型','添加时间');
            $this->showView($data,'./Public/Admin/Tpl/index.html');
        }
	}
	
	
    /**
     * 新增数据
     */
    public function add(){
    	if (IS_POST){
    		$this->addData($this->model,'添加成功|添加失败','index');
    	}else {
			$this->showView();
    	}
    }

    /**
     * 删除数据
     * POST请求为批删，GET请求为删除单条
     */
    public function del(){
        $this->delData($this->model,'删除成功|删除失败|ajax');
    }
    
    
	/**
     * 编辑数据
     */
    public function edit(){
    	if (IS_POST){
    		//更新操作
    		$this->editData($this->model,'修改成功|修改失败','index');
    	}else {
    		//页面视图
    		$field = 'pk_id,name,action,type';
    		$data['info'] = $this->model->where('pk_id = %d',I('pk_id'))->field($field)->find();
    		$this->showView($data);
    	}
    }
    
}
?>